<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<script>
// Ensure correct behavior of canvas with fillRect+shadow after scaling. A blue and red checkered pattern should be displayed.

var canvas = document.createElement('canvas');
document.body.appendChild(canvas);
canvas.setAttribute('width', '1000');
canvas.setAttribute('height', '1000');
var ctx = canvas.getContext('2d');

ctx.scale(2, 2);
ctx.shadowOffsetX = 100;
ctx.shadowOffsetY = 100;
ctx.fillStyle = 'rgba(0, 0, 255, 1)';

ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
ctx.fillRect(50, 50, 50, 50);

ctx.shadowColor = 'rgba(255, 0, 0, 0.3)';
ctx.fillRect(50, 150, 50, 50);

ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
ctx.shadowBlur = 10;
ctx.fillRect(150, 50, 50, 50);

ctx.shadowColor = 'rgba(255, 0, 0, 0.3)';
ctx.fillRect(150, 150, 50, 50);

function testPixelShadow(x, y, color)
{
    assert_array_equals(ctx.getImageData(x, y, 1, 1).data, color);
}

function testPixelShadowAlpha(x, y, color)
{
    var data = ctx.getImageData(x, y, 1, 1).data;
    assert_array_equals(data.slice(0,3), color.slice(0,3));
    assert_approx_equals(data[3], color[3], 20);
}

var testPixelShadowScenarios = [
    ['Verify solid shadow 1', 201, 205, [255, 0, 0, 255]],
    ['Verify solid shadow 2', 298, 298, [255, 0, 0, 255]],
    ['Verify solid shadow 3', 201, 298, [255, 0, 0, 255]],
];

var testPixelShadowAlphaScenarios = [
    ['Verify solid alpha shadow 1', 201, 405, [255, 0, 0, 76]],
    ['Verify solid alpha shadow 2', 298, 405, [255, 0, 0, 76]],
    ['Verify solid alpha shadow 3', 205, 498, [255, 0, 0, 76]],

    ['Verify blurry shadow 1', 398, 205, [255, 0, 0, 83]],
    ['Verify blurry shadow 2', 501, 205, [255, 0, 0, 83]],
    ['Verify blurry shadow 3', 500, 300, [255, 0, 0, 53]],

    ['Verify blurry alpha shadow 1', 398, 405, [255, 0, 0, 24]],
    ['Verify blurry alpha shadow 2', 405, 501, [255, 0, 0, 24]],
];

generate_tests(testPixelShadow, testPixelShadowScenarios);
generate_tests(testPixelShadowAlpha, testPixelShadowAlphaScenarios);

</script>
</body>
